/**
 * Created by seeker910 on 2018/5/8.
 */
Rsd.define('Rsd.Faith.pages.FiscalDTPiaoJuXinXiPage', {
    extend: 'Rsd.container.Page',
    requires: ['Rsd.container.FieldSet',
        'Rsd.Faith.controls.XiaoQuListView',
        'Rsd.control.Grid',
        'Rsd.control.GridToolBar',
        'Rsd.control.PagingBar',
        'Rsd.control.Text',
        'Rsd.controlEx.ComboBoxEx',
        'Rsd.controlEx.ComboBoxEnum',
        'Rsd.Faith.stores.KaiFaShangStore',
        'Rsd.Faith.stores.WuYeGongSiStore',
        'Rsd.Faith.stores.YeZhuWeiYuanHuiStore'
    ],
    xtype:'dtpiaoju-page',
    modelType: 'FiscalPiaoJuXinXiDtBiaoModel',
    layout:'border',
    items:[
        {
            region: 'west',
            xtype:'list-xiaoqu',
            border:true,
            itemClick:'item_click',
            margin: '0 10 0 0',
            width:300
        },
        {
            xtype:'grid',
            region: 'center',
            label:{
                xtype: 'grid-tool-bar',
                height:60,width:'100%',
                newButtons:[
                    {xtype:'button',text:'新增小区并缴存',width:150,style:{fontSize:'120%'},handler:'btn_new_save' },
                    {xtype:'label',width:550,text:'先查询到要缴存的小区，点击【缴存】录入楼栋信息并缴存；若小区不存在点击【新增小区并缴存】'}],
                //searchColumns:[{name:'DanYuanHao',text:'单元'}],
                searchHandler:'loadLouDongRows'
            },
            //footBar:{xtype:'paging-bar',indexChanged:'pageIndexChanged'},
            //{"XiaoQuBianHao":"7600","LouDongHao":null,"DanYuanCount":1,"BianHaoCount":1,"Xiao_qu_bian_hao":"7600","Lou_dong_hao":null}
            columns: [
                {
                    "text": "序号",
                    "xtype": "index",
                    "width": 40,
                    "sortable": false
                },
                {
                    "xtype": "string",
                    "name": "XiaoQuBianHao",
                    "text": "小区编号",
                    "sortable": false,
                    "width": 80,
                    "nobr": true
                },
                {
                    "xtype": "string",
                    "name": "LouDongHao",
                    "text": "楼栋号",
                    "sortable": false,
                    align:'center',
                    "width": 100,
                    "format":"format_loudonghao",
                    "nobr": true
                },
                {
                    "xtype": "string",
                    "name": "DanYuanHao",
                    "text": "单元号",
                    "sortable": false,
                    "width": 100
                },
                {
                    "xtype": "number",
                    "name": "HuShu",
                    "text": "户数",
                    "precision": 0,
                    "sortable": false,
                    "width": 50,
                    "nobr": true
                },

                {
                    "name": "Remark",
                    "text": "备注",
                    "sortable": false,
                    "width": 150,
                    "nobr": true
                }
            ]

        }
    ],


    /*
     * */
    constructor: function (config) {
        config = config || {};
        Rsd.apply(this, config);

        var me = this;
        var _grid = this.items[1];
        _grid.dataSource = Rsd.app.getService('info.getloudonglist');
        _grid.openItem= function(record){me.openItem(record);};
    },
    load:function load() {
        var me = this;
        setTimeout(function () {
            me.items[0].loadData();
        },50);
    },
    item_click:function(item)
    {
        var me = this;
        me.__xiao_qu_bian_hao = item.content.key;
        me.loadLouDongRows();
    },
    btn_find:function btn_find()
    {
        var me = this;
        var _name = this.getItemByName('xiaoqu_mc').getValue();


        var _store = Rsd.create('Rsd.Faith.stores.ListStore',{});
        _store.load({modelType:'Rsd.Faith.Models.InfoXiaoQuWuYeBiaoModel',where:[{name:'mingcheng',op:'like',value:'%' + _name + '%'}]},function (data) {


            me.items[1].items[0].loadData(data.data.rows);

            if(data.data.rows.length == 0)
            {
                Rsd.popup("未查询到相关小区");
            }
        });

    },
    btn_new_save:function btn_new_save() {
        Rsd.create('Rsd.Faith.dialogs.FiscalDTJiaoCunDialog',{isNew:true}).showDialog().load();
    },
    format_loudonghao:function format_loudonghao(row) {

        // console.log(row);

        var me = this;
        var _fn = function () {

            Rsd.create('Rsd.Faith.dialogs.FiscalDTJiaoCunDialog', {isNew: false}).showDialog().load();
        }

        if(Rsd.isEmpty(row['LouDongHao']))
        {
            return [Rsd.text('-'),Rsd.newLine(),Rsd.button('缴 存',_fn)];
        }
        return [ Rsd.text(row['LouDongHao']),Rsd.newLine(),Rsd.button('缴 存',_fn)]
    },
    /*
     * */
    loadLouDongRows:function loadLouDongRows( ) {

        var me = this;
        var  bian_hao= me.__xiao_qu_bian_hao;
        if(Rsd.isEmpty(bian_hao))
        {
            Rsd.alert("请选择小区");
            return;
        }

        var grid = me.items[1];
        Rsd.showWaiting(this.id,grid);
        grid.loadData({xiaoqubianhao:bian_hao},function(){

            Rsd.closeWaiting(me.id);
        });

    }

});